//
// Created by 王乐 on 2022/2/5.
//

#include "LeQuadGameObject.h"
#include "LeQuadRenderer.h"
#include "LeRigidBody.h"


LeQuadGameObject::LeQuadGameObject()
{}

LeQuadGameObject::~LeQuadGameObject()
{

}

void LeQuadGameObject::Initialize()
{
    strName = "MyQuad";



    // RigidBody
    // ---------
    b2BodyDef bodyDef;
    bodyDef.userData.pointer = reinterpret_cast<uintptr_t>(this);
    bodyDef.type = b2_staticBody;
    bodyDef.position.Set(m_Transform.m_Position.x, m_Transform.m_Position.y);
    bodyDef.angle = m_Transform.m_Rotation.z;

    b2FixtureDef fixtureDef;
    b2PolygonShape polygonshape;
    polygonshape.SetAsBox(m_Transform.m_Scale.x / 2, m_Transform.m_Scale.y / 2);
    fixtureDef.shape = &polygonshape;
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.3f;
    fixtureDef.restitution = 0.1f;

    LeRigidBody* pRigidBody = new LeRigidBody();
    pRigidBody->initRigidBody(bodyDef, fixtureDef);

    // Renderer
    // --------
    LeQuadRenderer* pRenderer = new LeQuadRenderer();
    pRenderer->initRenderer(this, "/Users/wangle/CLionProjects/Leste/res/shader/simplepng.vs", "/Users/wangle/CLionProjects/Leste/res/shader/simplepng.fs");
    pRenderer->addSprite(m_DiffuseMapPath);

    // Initialize Components
    initComponents(pRenderer, pRigidBody, nullptr, nullptr);
}

void LeQuadGameObject::setParameter(const glm::vec3 &position, const glm::vec3 &rotation, const glm::vec3 &scale,
                                    const char *diffusemappath)
{
    m_DiffuseMapPath = diffusemappath;
    // Transform
    // ---------
    m_Transform.setPosition(position.x,position.y,position.z);
    m_Transform.setRotation(rotation.x,rotation.y,rotation.z);
    m_Transform.setScale(scale.x,scale.y,scale.z);
//    m_Transform.setPosition(0.0f, 0.0f, 0.0f);
//    m_Transform.setRotation(90.0f / 180.0f * 3.14, 0, 0);
//    m_Transform.setScale(10, 10, 1);
}
